<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript 打印金字塔</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>





<script>

    var y = prompt("请输入金字塔的层数：");

    for (var i = 1 ; i <= y ; i++){   //执行的行数，遍数

        var t = y - i;          //起一个变量用于计算空格的个数
        for (var a = 1 ; a <= t ; a++ ){

            document.write("&nbsp");

        }

        var h = i * 2 -1;               //起一个变量用于计算*号的个数
        for (var x = 1 ; x <= h ; x++){

            document.write("*");

        }
        document.write("<br>");

    }



</script>



</body>
</html>